#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# PATH=$PATH:/usr/local/bin:/usr/local/sbin
# npm test

# eslint --fix ./src --ext .vue,.js,.ts

if ! type node >/dev/null 2>&1; then
  echo 'node 未安装'
  if [ -d "$HOME/.nvm" ]; then
    echo "有.nvm这个目录"

    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

    matchNvmUseNodeVersion=$(nvm current)
    if [ "$matchNvmUseNodeVersion" == "none" ]; then
      echo "没有找到NVM设置的Node版本,请执行nvm install --lts"
      exit 1
    else
      echo "检测到nvm设置了有效的Node版本: $matchNvmUseNodeVersion"
      export PATH="$NVM_DIR/versions/node/$matchNvmUseNodeVersion/bin:$PATH"
    fi
  fi

else
  echo 'node 已安装'
  nodeVersion=$(node -v)
  npmVersion=$(npm -v)
  echo "node 版本:$nodeVersion"
  echo $(which node)
  echo "npm 版本:$npmVersion"
  echo $(which npm)
fi

npx lint-staged
